#include "LedColor.h"
#include "SnakeStateLedPresentationHardwareInfo.h"

#include <SoftwareSerial.h>

enum SnakeMovingState
{
	StayStill = 0b00000000,
	MoveForward = 0b00010001,
	MoveBackward = 0b00010010,
	MoveLeftward = 0b00010100,
	MoveRightward = 0b00011000
};

LedColor GetStateColor(SnakeMovingState state)
{
	switch (state)
	{
	case MoveForward:
		return LedColor(0, 255, 0);
	case MoveBackward:
		return LedColor(255, 0, 0);
	case MoveLeftward:
		return LedColor(255, 0, 255);
	case MoveRightward:
		return LedColor(0, 255, 255);
	default:
		return LedColor(255, 255, 255);
	}
}

SoftwareSerial* bluetoothSerial;
SnakeMovingState state;

void LigthenCurrentState()
{
	using namespace SnakeStateLedPresentationHardwareInfo;
	GetStateColor(state).Lighten(LED_R, LED_G, LED_B);
}

void setup() 
{
	using namespace SnakeStateLedPresentationHardwareInfo;

	bluetoothSerial = new SoftwareSerial(BLUETOOTH_TXD, BLUETOOTH_RXD);
	bluetoothSerial->begin(BLUETOOTH_SERIAL_BAUDRATE);

	pinMode(LED_R, OUTPUT);
	pinMode(LED_G, OUTPUT);
	pinMode(LED_B, OUTPUT);

	state = SnakeMovingState::StayStill;
	LigthenCurrentState();
}

void loop()
{
	if (bluetoothSerial->available())
	{
		state = (SnakeMovingState)(bluetoothSerial->read());
		LigthenCurrentState();
	}
}
